package net.jeeframework.fileuplod.util;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class FileSystemValidator {

	private static final Log log = LogFactory.getLog(FileSystemValidator.class);

	public static boolean isFileAllowed(String filename) {
		if (filename == null || filename.trim().length() == 0) { // 文件名不能为空
			log.warn("验证文件失败：文件名不能为空");
			return false;
		}

		String extension = FilenameUtils.getExtension(filename);
		if (extension == null || extension.trim().length() == 0) { // 没有文件名
			log.warn("验证文件失败：文件没有后缀名");
			return false;
		}

		if (FileSystemConfig.RESOURCES.contains(extension)) {
			return true;
		}

		log.info("验证文件失败：文件类型不允许上传");

		return false;
	}

}